package com.llkj.qingnianguoxue.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.base.BaseActivity;
import com.llkj.qingnianguoxue.base.ConstantUserInfo;
import com.llkj.qingnianguoxue.base.MyApplication;
import com.llkj.qingnianguoxue.http.HttpMethod;
import com.llkj.qingnianguoxue.util.MyShare;

/**
 * 邀请好友
 */
public class InviteFriendActivity extends BaseActivity implements View.OnClickListener, MyShare.ShareResultCallback {
    private TextView tvInviteCode;//邀请码
    private LinearLayout llWechat, llQQ, llCircle, llSina, llSpace;//微信，Qq,朋友圈，新浪，qq空间
    private String mInvitationCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_invite_friend);
        setTitle("邀请好友", true, TITLE_TYPE_IMG, R.drawable.icon_back, false, TITLE_TYPE_TEXT, null);

        initView();
        initListener();
    }

    private void initView() {
        initStatusbar(TSATUSBAR_TYPE_BLACK_TEXT,rlTitle,R.color.gray_bar);
        tvInviteCode = (TextView) findViewById(R.id.tv_invite_code);

        llWechat = (LinearLayout) findViewById(R.id.ll_wechat);
        llQQ = (LinearLayout) findViewById(R.id.ll_qq);
        llCircle = (LinearLayout) findViewById(R.id.ll_friend_circle);
        llSina = (LinearLayout) findViewById(R.id.ll_sina);
        llSpace = (LinearLayout) findViewById(R.id.ll_qq_space);

        mInvitationCode = MyApplication.getInstance().sputil.getString(ConstantUserInfo.INVITATION_CODE);
        tvInviteCode.setText(mInvitationCode);
    }

    private void initListener() {
        llWechat.setOnClickListener(this);
        llQQ.setOnClickListener(this);
        llCircle.setOnClickListener(this);
        llSina.setOnClickListener(this);
        llSpace.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        String title = "邀请好友";
//        String content = "起范儿app邀请好友分享邀请码" + mInvitationCode;
        String content = "注册时输入邀请码，双方将获得积分奖励";
        String uid = MyApplication.getInstance().sputil.getString(ConstantUserInfo.USER_ID);
        String linkUrl = String.format(HttpMethod.SHARE_INVITE, uid);
        String imageUrl = null;
        switch (v.getId()) {
            case R.id.ll_wechat:
                MyShare.share(this, 1, title, content, imageUrl, linkUrl, this);
                break;
            case R.id.ll_qq:
                MyShare.share(this, 3, title, content, imageUrl, linkUrl, this);
                break;
            case R.id.ll_friend_circle:
                MyShare.share(this, 2, title, content, imageUrl, linkUrl, this);
                break;
            case R.id.ll_sina:
                MyShare.share(this, 4, title, content, imageUrl, linkUrl, this);
                break;
            case R.id.ll_qq_space:
                MyShare.share(this, 5, title, content, imageUrl, linkUrl, this);
                break;
        }
    }

    @Override
    public void shareResultCallBack(int result) {
        switch (result) {//1成功，2失败，3取消
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
        }
    }
}
